Seedha content par jao
🤖 Python Hindi Bot
Namaste! Main Python Hindi Bot hoon 🐍
Python ya AI se related kuch bhi type karke pucho, ya neeche se quick sawaal chuno.
WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
⇧
Python Hindi Logo
Python in Hindi | Programming Education
🎓 100% Free · Hindi me · Beginner se Career tak

Python Tutorial in HindiiLearn Python Programming for Free

Python, AI, Data Analytics aur SQL ek hi jagah, simple Hindi me. Padho, browser me code chalao, projects banao aur career shuru karo.

main.py
# Python seekho, Hindi me naam = "Ravi" for i in range(3): print("Namaste", naam)
▸ python main.py
🐍 Python 🤖 AI & ML 📊 Data 🗄️ SQL

Chahe Student ho ya Professional, yahan aapke liye sab hai

Apna card chuno, seedha sahi jagah pahunch jaoge.

🎓

Student ho?

School ya college me ho? Python zero se seekho, notes aur cheat sheets ke saath.

  • Python basics se OOP tak
  • Notes, PDFs aur Cheat Sheets
  • Browser me practice, kuch install nahi
💼

Working Professional ho?

Kaam ke saath nayi skill jodo: data, SQL aur AI se apna kaam tez karo.

  • Pandas, NumPy, Excel, Power BI
  • SQL aur MySQL databases
  • Automation aur AI Tools
🚀

Job ya Career change?

Projects banao, interview ki taiyari karo aur sahi roadmap follow karo.

  • Real projects, portfolio ke liye
  • Python aur SQL interview questions
  • AI Engineer, Data Scientist roadmap

Python Hindii Kaise Kaam Karta Hai?

Ek hi jagah 4 layers: seekho, practice karo, skills banao aur career shuru karo. Har layer ek step hai, us par click karke seedha wahan pahuncho. Computer par drag karke 3D me ghumao bhi.

Layer 1 · Seekho

Python Basics se Advanced tak

Variables, loops, functions se OOP tak, sab simple Hindi me. Yahin se shuru karo.

Naye ho? 3 step me shuru karo

💻 Online Code Editor

Browser me hi code likho aur turant chalao

Koi software install nahi. Code likho, Run dabao aur result usi waqt dekho.

  • Python, Java, C, C++, JavaScript, HTML aur aur bhi languages
  • input(), graphs aur multi-file HTML project bhi chalte hain
  • Mobile aur computer, dono par chalta hai
main.py
naam = input("Naam batao: ") for i in range(3): print("Namaste", naam)
▸ python main.py
PythonJavaCC++JavaScriptHTML

Python se AI tak ka poora rasta

8 steps, ek ke baad ek. Aage-peeche ghumao aur apni stage se seedha shuru karo.

Step 1 🐍

Python Basics

IntroductionVariablesData TypesOperatorsInput & OutputConditionsLoops
Start Python →
Step 2 💻

Python Intermediate

ListsTuplesSetsDictionariesStringsModulesFile Handling
Continue Python →
Step 4 🗄️

SQL & Databases

SQL BasicsMySQLSELECTINSERTUPDATEDELETEJOIN
Learn SQL →
Step 5 📊

Data Analytics

NumPyPandasData CleaningData VisualizationMatplotlibExploratory Data Analysis
Learn Data Analytics →
Step 6 🤖

Machine Learning

ML BasicsSupervised & Unsupervised LearningRegressionClassificationModel EvaluationScikit-learn
Learn Machine Learning →
Step 7 🧠

Artificial Intelligence

AI FundamentalsGenerative AIAI ToolsPrompt EngineeringLLM ConceptsAI Automation
Explore AI →
Step 8 🚀

Projects & Career

Python ProjectsAI ProjectsData ProjectsPortfolioGitHubInterview PreparationCareer Roadmap
Build Your Career →
Step 1 / 8

Python में Inheritance क्या है? | Code Reuse & Parent-Child Class Explained

Python me Inheritance kya hai - Code Reuse and Parent-Child Class Explained
Python Inheritance

OOP के चार मुख्य स्तंभों में से एक और बहुत important concept है — Inheritance। यह वही concept है जिसने पिछले lesson के Method Overriding वाले example में Dog(Animal) को possible बनाया था। अब इसे पूरी तरह, step-by-step समझते हैं।

अगर आपने अभी Python Classes & Objects नहीं पढ़ा है, तो पहले उसे पढ़ना जरूरी है, क्योंकि Inheritance पूरी तरह Classes पर आधारित है। Examples खुद run करने के लिए हमारा Online Python Editor & Compiler use कर सकते हैं।

⚠️ इस Lesson का Scope: इस lesson में Inheritance की बुनियादी समझ, Method Overriding, super(), और Multilevel Inheritance के basic idea को ही कवर किया जाएगा। Encapsulation, Abstraction और Multiple/Hierarchical Inheritance जैसी advanced details को आगे dedicated lessons में अलग से समझाया जाएगा।

Inheritance क्या है?

Inheritance OOP का वह सिद्धांत है, जिसमें एक Class दूसरी Class की properties और behavior (attributes और methods) को अपने-आप प्राप्त (inherit) कर लेती है, बिना उन्हें दोबारा लिखे।

सरल भाषा में — Inheritance का मतलब है: "मुझे अपने माता-पिता से कुछ चीज़ें विरासत में मिल जाती हैं, बिना मुझे उन्हें दोबारा बनाना पड़े।"

Parent Class क्या है?

Parent Class (जिसे Base Class या Super Class भी कहते हैं) वह Class है, जिसकी properties और methods किसी दूसरी Class को दी जाती हैं।

Example
class Animal: def eat(self): print("This animal eats food")

यहाँ Animal एक Parent Class है।

Child Class क्या है?

Child Class (जिसे Derived Class या Sub Class भी कहते हैं) वह Class है, जो किसी Parent Class से properties और methods को inherit करती है।

Example
class Animal: def eat(self): print("This animal eats food") class Dog(Animal): pass d = Dog() d.eat()

Output:

This animal eats food

class Dog(Animal): में Animal को brackets में लिखना ही Dog को Animal का Child Class बना देता है। Dog में खुद कोई eat() method नहीं लिखा, फिर भी वह इस्तेमाल हो गया — यही Inheritance है।

Try it Yourself »
Animal (Parent Class) │ ▼ Dog (Child Class)
🎥 Video में पूरा Topic समझें

Parent से Methods और Attributes Inherit करना

Child Class को Parent Class के methods ही नहीं, attributes भी अपने-आप मिल जाते हैं।

Example
class Animal: def set_name(self, name): self.name = name def show_name(self): print("Name:", self.name) class Dog(Animal): pass d = Dog() d.set_name("Tommy") d.show_name()

Output:

Name: Tommy

Dog ने set_name() और show_name() — दोनों methods Animal से inherit कर लिए, बिना उन्हें दोबारा लिखे।

Try it Yourself »

Child Class में अपना Feature जोड़ना

Child Class सिर्फ Parent की चीज़ें इस्तेमाल ही नहीं करती — वह अपने खुद के नए methods और attributes भी जोड़ सकती है।

Example
class Animal: def eat(self): print("This animal eats food") class Dog(Animal): def bark(self): print("Dog barks: Woof!") d = Dog() d.eat() # Parent से मिला d.bark() # खुद का नया feature

Output:

This animal eats food Dog barks: Woof!

eat() method Animal से inherit हुआ, जबकि bark() सिर्फ Dog के पास है — Animal के पास bark() नहीं है।

Try it Yourself »

Code Reuse

Inheritance का सबसे बड़ा practical फायदा है Code Reuse — यानी एक ही code को बार-बार लिखने की बजाय, उसे एक जगह लिखकर कई Classes में reuse करना।

Example — बिना Inheritance के (ज्यादा Code, Repetition)
class Dog: def eat(self): print("This animal eats food") def bark(self): print("Woof!") class Cat: def eat(self): print("This animal eats food") def meow(self): print("Meow!")

यहाँ eat() method दोनों Classes में अलग-अलग लिखा गया — same code दो बार।

Example — Inheritance के साथ (Code Reuse)
class Animal: def eat(self): print("This animal eats food") class Dog(Animal): def bark(self): print("Woof!") class Cat(Animal): def meow(self): print("Meow!") d = Dog() c = Cat() d.eat() c.eat()

Output:

This animal eats food This animal eats food

eat() सिर्फ एक बार, Animal में लिखा गया, और Dog व Cat दोनों ने उसे reuse किया — यही Inheritance का मुख्य फायदा है।

Try it Yourself »

Method Overriding का Basic Concept

कभी-कभी Child Class को Parent के किसी method का behavior बदलना होता है — इसके लिए Child Class में उसी नाम का method फिर से define कर दिया जाता है, जिसे Method Overriding कहते हैं।

Example
class Animal: def sound(self): print("Animal makes a sound") class Dog(Animal): def sound(self): print("Dog barks: Woof!") a = Animal() d = Dog() a.sound() d.sound()

Output:

Animal makes a sound Dog barks: Woof!

Dog ने Animal के sound() method को अपने तरीके से फिर से लिख दिया — Python हमेशा Child Class के method को पहले priority देता है।

Try it Yourself »

super() का Basic Use

super() का इस्तेमाल Child Class के अंदर से Parent Class के method को call करने के लिए किया जाता है — भले ही Child Class ने उस method को override कर दिया हो।

Example
class Animal: def sound(self): print("Animal makes a sound") class Dog(Animal): def sound(self): super().sound() print("Dog barks: Woof!") d = Dog() d.sound()

Output:

Animal makes a sound Dog barks: Woof!

super().sound() ने पहले Parent Class Animal के original sound() को call किया, फिर Child Class का अपना code चला। इस तरह Dog अपने Parent की functionality को पूरी तरह हटाने की बजाय, उसे extend कर पाया।

Try it Yourself »

Multilevel Inheritance का Basic Idea

Multilevel Inheritance में एक Class किसी दूसरी Child Class से आगे inherit करती है — यानी Inheritance की एक chain बन जाती है (Parent → Child → Grandchild)।

Animal │ ▼ Dog │ ▼ Puppy
Example
class Animal: def eat(self): print("This animal eats food") class Dog(Animal): def bark(self): print("Dog barks: Woof!") class Puppy(Dog): def weep(self): print("Puppy weeps: Yip!") p = Puppy() p.eat() p.bark() p.weep()

Output:

This animal eats food Dog barks: Woof! Puppy weeps: Yip!

Puppy को Dog से bark() मिला, और Dog के through Animal से eat() भी मिल गया — इसी chain को Multilevel Inheritance कहते हैं।

Try it Yourself »

Real-World Employee Example

अब Inheritance को एक practical, real-world जैसी situation में देखते हैं — एक company में अलग-अलग तरह के employees।

Example
class Employee: def set_details(self, name, salary): self.name = name self.salary = salary def show_details(self): print("Name:", self.name) print("Salary:", self.salary) class Manager(Employee): def set_team_size(self, team_size): self.team_size = team_size def show_team(self): print("Team Size:", self.team_size) m1 = Manager() m1.set_details("Ankit", 60000) m1.set_team_size(8) m1.show_details() m1.show_team()

Output:

Name: Ankit Salary: 60000 Team Size: 8

Manager एक special तरह का Employee है — उसे Employee की सारी basic details (set_details(), show_details()) मिल गईं, और साथ में उसने अपना खुद का feature (team_size) भी जोड़ लिया। यही Inheritance का असली, practical इस्तेमाल है।

Try it Yourself »

Common Beginner Mistakes

❌ Child Class में Parent का नाम Brackets में लिखना भूल जाना
class Dog: # Animal नहीं लिखा pass d = Dog() d.eat() # AttributeError
✅ सही तरीका
class Dog(Animal): pass
❌ super() को सही तरीके से इस्तेमाल न करना
class Dog(Animal): def sound(self): Animal.sound() # self मिसिंग, गलत तरीका
✅ सही तरीका
class Dog(Animal): def sound(self): super().sound()
❌ यह सोचना कि Child के Changes, Parent को भी प्रभावित करते हैं

Child Class में नया method जोड़ने या किसी method को override करने से Parent Class पर कोई असर नहीं पड़ता। Inheritance सिर्फ एक दिशा में चलता है — Parent से Child की तरफ।

❌ Parent के पास न होने वाला Method, Parent के Object से Call करने की कोशिश
a = Animal() a.bark() # AttributeError, क्योंकि bark() सिर्फ Dog में है

Child के नए methods सिर्फ Child के Objects पर ही काम करते हैं — Parent के Objects को वे features नहीं मिलते।

Exercise ?

Child Class से Parent Class के किसी method को call करने के लिए किसका इस्तेमाल किया जाता है?

self()
super()
parent()

Practical Coding Challenge

अब खुद अपने Online Python Editor में यह challenge solve कीजिए:

  1. एक Vehicle Parent Class बनाइए जिसमें set_details(self, brand, speed) और show_details(self) methods हों।
  2. एक Car नाम की Child Class बनाइए जो Vehicle से inherit करे, और उसमें अपना एक नया method honk(self) जोड़िए।
  3. Car का एक Object बनाकर Parent और Child — दोनों के methods को call कीजिए।
  4. Vehicle में sound() नाम का एक method बनाइए, और Car में उसे override करके super() की मदद से Parent का version भी साथ में call कीजिए।
  5. एक SportsCar नाम की तीसरी Class बनाइए जो Car से inherit करे (Multilevel Inheritance), और उसमें एक नया feature जोड़िए।

Quick Revision

Conceptमतलब
Inheritanceएक Class द्वारा दूसरी Class की properties/methods प्राप्त करना
Parent Classवह Class जिससे features दिए जाते हैं
Child Classवह Class जो features प्राप्त करती है — class Child(Parent):
Method OverridingChild द्वारा Parent के method को फिर से define करना
super()Child से Parent के method को call करने के लिए
Multilevel InheritanceParent → Child → Grandchild जैसी chain

FAQ

Python में Inheritance क्या है?

Inheritance OOP का वह सिद्धांत है, जिसमें एक Class (Child) दूसरी Class (Parent) की properties और methods को अपने-आप प्राप्त कर लेती है।

Parent Class और Child Class में क्या फर्क है?

Parent Class वह है जिसकी properties और methods share की जाती हैं, जबकि Child Class वह है जो उन्हें inherit करती है और अपने खुद के नए features भी जोड़ सकती है।

Inheritance का सबसे बड़ा फायदा क्या है?

Inheritance का सबसे बड़ा फायदा Code Reuse है — एक जैसा code बार-बार अलग-अलग Classes में लिखने की बजाय, उसे एक जगह लिखकर कई Classes में reuse किया जा सकता है।

super() का इस्तेमाल क्यों किया जाता है?

super() का इस्तेमाल Child Class से Parent Class के method को call करने के लिए किया जाता है, खासकर तब जब वह method override भी किया गया हो।

Multilevel Inheritance क्या है?

Multilevel Inheritance में एक Class किसी ऐसी Class से inherit करती है, जो खुद भी किसी और Class से inherit कर रही होती है — जिससे Parent → Child → Grandchild जैसी एक chain बन जाती है।

Summary

Inheritance = Child Class को Parent Class से features विरासत में मिलना, बिना उन्हें दोबारा लिखे।

इस lesson में आपने सीखा कि Inheritance क्या है, Parent और Child Class क्या होते हैं, Methods और Attributes कैसे inherit होते हैं, Child Class में अपना feature कैसे जोड़ें, Code Reuse कैसे होता है, Method Overriding और super() कैसे काम करते हैं, और Multilevel Inheritance का basic idea क्या है।

Inheritance OOP का एक बहुत powerful tool है जो code को organized और reusable बनाता है। अब ऊपर दिया गया coding challenge खुद अपने Online Editor में solve करें।

Related Articles

🧑‍💻 Python Coding Lab

Python code likho, run karo aur practice karo — directly browser mein.